{extend name="../../admin/view/main"}

{block name="button"}
<!--{if auth("record.car_record_analyze/overview")}-->
<button class='layui-btn layui-btn-sm layui-btn-primary' data-modal='{:url("record.car_record_analyze/overview")}'>未喷漆分析饼状图</button>
<!--{/if}-->
{/block}

{block name="content"}
<div class="layui-tab layui-tab-card">

    <ul class="layui-tab-title notselect">
        {php}$types = ['ta' => '全部', 't1' => '其他原因', 't2' => '司机原因', 't3' => '延期喷漆', 't4' => '甲方原因'];{/php}
        {foreach $types as $k=>$v}
            {if isset($type) and 't'.$type eq $k}
                <li class="layui-this" data-open="{:url('index')}?type={$k}">{$v}</li>
            {else}
                <li data-open="{:url('index')}?type={$k}">{$v}</li>
            {/if}
        {/foreach}
    </ul>

    <div class="layui-tab-content">

        <table class="layui-table margin-top-10" lay-skin="line">
            {notempty name='list'}
            <thead>
            <tr>
                <th class='nowrap'>ID</th>
                <th class='nowrap'>司机信息</th>
                <th class='nowrap'>邀约情况</th>
                <th class='nowrap'>归属原因</th>
                <th class='nowrap'>对接日期</th>
            </tr>
            </thead>
            {/notempty}
            <tbody>
            {foreach $list as $key=>$vo}
                <tr data-dbclick {if $vo.id eq input('show_id') } style="border: 2px solid red" {/if} >
                <td class='nowrap'>
                    <div><span class="color-text">{$vo.id|default='-'}</span></div>
                </td>
                <td class="nowrap">
                    <!--司机--><div>司机:{$vo.username}</div>
                    <!--车牌--><div>车牌:{$vo.plate_number}</div>
                    <!--电话--><div>电话:{$vo.phone}</div>
                </td>
                <td class="nowrap" data-tips-text="{$vo.invite_remark|default='-'}">
                    <!--首次邀约日期-->
                    <div>首次邀约日期: {$vo.time_invite}</div>
                    <!--首次邀约情况-->
                    <div>首次邀约情况: <span style="color: #0000FF">{$vo.invite_remark|mb_substr=0,20,'UTF-8'}</span></div>
                </td>

            <td class="nowrap">
                <!--{if auth("changeReason")}-->
                <div class="layui-col-xs12 relative block margin-top-10">
                    <div class="layui-input-inline">
                        <select class="layui-select layui-select-select" data-value="{$vo.id}" name="analyze_reason" lay-filter="analyze-reason">
                            {foreach $analyzeReasons as $analyzeReasonId => $analyzeReason}
                            {if isset($vo.analyze_reason) and $analyzeReasonId eq $vo.analyze_reason}
                                <option selected value="{$analyzeReasonId}" data-value="id#{$vo.id};analyze_reason#{$analyzeReasonId}">{$analyzeReason}</option>
                            {else}
                              <option value="{$analyzeReasonId}" data-value="id#{$vo.id};analyze_reason#{$analyzeReasonId}">{$analyzeReason}</option>
                            {/if}
                            {/foreach}
                        </select>
                    </div>
                </div>
                <!--{else}-->
                <div>{$vo.analyze_reason_text}</div>
                <!--{/if}-->
            </td>

            <td class="nowrap">
                    <!--对接日期--><div>{$vo.time_docking}</div>
                </td>

                </tr>
            {/foreach}
            </tbody>
        </table>
        {empty name='list'}<span class="notdata">没有记录哦</span>{else}{$pagehtml|raw|default=''}{/empty}
    </div>
</div>

<script>
    layui.use(['form', 'layer'], function() {
        $('.layui-select-select').on('change', function() {
            let analyze_reason = $(this).val()
            let id = $(this).data('value')

            // 发起Ajax请求
            $.ajax({
                url: "{:url('changeReason')}",
                type: 'POST',
                data: {
                    id: id,
                    analyze_reason: analyze_reason
                },
                success: function(res) {
                    layer.msg(res.info);
                },
                error: function(xhr, status, error) {
                    console.log(xhr.responseText);
                }
            });
        });

        // 绑定事件到select元素
        form.render(null, 'analyze_reason');
    });
</script>
{/block}